package com.zsc.newbuds.mapper;

import com.zsc.newbuds.entity.Record;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author D
 */
public interface RecordMapper {

    /**
     * 增加记录
     * @param record
     */
    @Options(useGeneratedKeys = true,keyProperty = "recordId")
    @Insert("insert into record(donor,startAddress,donationName,userId,recycle_id) values(#{donor},#{startAddress},#{donationName},#{userId},#{recycleId})")
    void addRecord(Record record);

    /**
     * 获取记录列表
     * @return
     */
    @Select("select * from record")
    List<Record> getRecordList();

    /**
     * 获取记录
     * @param id
     * @return
     */
    @Select("select * from record where record_id = #{recordId}")
    Record getRecordById(Integer id);

    /**
     * 获取状态为捐赠的记录
     * @return
     */
    @Select("select * from record where state = '捐献'")
    List<Record> getRecordByState();


    /**
     * 增加回收地区
     * @param recordId
     * @param area
     */
    @Update("update record set donationArea = #{area} where record_id = #{recordId}")
    void addDonationArea(Integer recordId,String area);
}
